package com.sskj.mine.verify;

import android.content.Context;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;

import com.hjq.toast.ToastUtils;
import com.sskj.common.util.CheckUtil;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPName;
import com.sskj.lib.base.BaseActivity;
import com.sskj.mine.R;
import com.sskj.mine.R2;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/05/01
 */
public class VerifyFirstActivity extends BaseActivity<VerifyFirstPresenter> {

    @BindView(R2.id.name_edt)
    EditText nameEdt;
    @BindView(R2.id.id_card_edt)
    EditText idCardEdt;
    @BindView(R2.id.submit_btn)
    Button submitBtn;

    @Override
    public int getLayoutId() {
        return R.layout.mine_activity_verify_first;
    }

    @Override
    public VerifyFirstPresenter getPresenter() {
        return new VerifyFirstPresenter();
    }

    @Override
    public void initView() {
        setTitle(getString(R.string.mine_verifyFirstActivity1));
    }

    @Override
    public void initData() {
        ClickUtil.click(submitBtn, () -> {
            if (isEmpty(nameEdt)) {
                ToastUtils.show(getString(R.string.mine_verifyFirstActivity2));
                return;
            }
            String reg = "^[\\u4e00-\\u9fa5]{2,4}";
            if (!getText(nameEdt).matches(reg)) {
                ToastUtils.show(getString(R.string.mine_verifyFirstActivity3));
                return;
            }

            if (isEmpty(idCardEdt)) {
                ToastUtils.show(getString(R.string.mine_verifyFirstActivity4));
                return;
            }
            if (!CheckUtil.isIdCard(getText(idCardEdt))) {
                ToastUtils.show(getString(R.string.mine_verifyFirstActivity5));
                return;
            }
            mPresenter.verifyFirst(nameEdt.getText().toString(), idCardEdt.getText().toString());
        });
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, VerifyFirstActivity.class);
        context.startActivity(intent);
    }

    public void verifyFirstSuccess() {
        ToastUtils.show(getString(R.string.mine_verifyFirstActivity6));
        finish();
    }

}
